package com.trmp.base.shoppingMng.dao;


import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.trmp.base.shoppingMng.entity.BaseShoppingStoreInfo;
import com.trmp.commons.dao.GenericRepository;

public interface ShoppingStoreInfoDao extends GenericRepository<BaseShoppingStoreInfo, Long>{

	public List<BaseShoppingStoreInfo> findByOrgID(Long orgId);
	
	@Query(value="select new BaseShoppingStoreInfo(b.shoppingId,b.cmpName,b.cmpAdd,b.chiffMobile) from BaseShoppingStoreInfo b where b.orgID=?1 and b.cmpName like ?2 and b.cmpAdd like ?3")
	public List<BaseShoppingStoreInfo> findByOrgIDAndCmpNameLikeAndCmpAddLike(long orgId,String name,String address,Pageable page);
	
	@Query(value="select new BaseShoppingStoreInfo(b.shoppingId,b.cmpName,b.cmpAdd,b.chiffMobile) from BaseShoppingStoreInfo b where b.orgID=?1 and b.cmpAdd like ?2")
	public List<BaseShoppingStoreInfo> findByOrgIDAndCmpAddLike(long orgId,String address,Pageable page);
	
	@Query(value="select new BaseShoppingStoreInfo(b.shoppingId,b.cmpName,b.cmpAdd,b.chiffMobile) from BaseShoppingStoreInfo b where b.orgID=?1 and b.cmpName like ?2")
	public List<BaseShoppingStoreInfo> findByOrgIDAndCmpNameLike(long orgId,String name,Pageable page);
	
	@Query(value="select new BaseShoppingStoreInfo(b.shoppingId,b.cmpName,b.cmpAdd,b.chiffMobile) from BaseShoppingStoreInfo b where b.orgID=?1")
	public List<BaseShoppingStoreInfo> findByOrgID(long orgId,Pageable page);
	
	@Query(value="select count(shoppingId) from BaseShoppingStoreInfo where orgID=?1 and cmpName like ?2 and cmpAdd like ?3")
	public Long countByOrgIDAndCmpNameLikeAndCmpAddLike(long orgId,String name,String address);
	
	@Query(value="select count(shoppingId) from BaseShoppingStoreInfo where orgID=?1 and cmpName like ?2")
	public Long countByOrgIDAndCmpNameLike(long orgId,String name);
	
	@Query(value="select count(shoppingId) from BaseShoppingStoreInfo where orgID=?1 and cmpAdd like ?2")
	public Long countByOrgIDAndCmpAddLike(long orgId,String address);
	
	@Query(value="select count(shoppingId) from BaseShoppingStoreInfo where orgID=?1")
	public Long countByOrgID(long orgId);
	
	@Modifying
	@Query(value="delete from BaseShoppingStoreInfo b where b.shoppingId=?1")
	public void deleteByShoppingId(Long shoppingId);
	
	public List<BaseShoppingStoreInfo> search(Long orgId,String name,String address,Pageable page);
	
	@Query(value="select b from BaseShoppingStoreInfo b left JOIN fetch b.shoppingFreeSet where b.shoppingId=?1")
	public BaseShoppingStoreInfo findByShoppingIdFetchFee(Long shoppingId);
}
